#include "modifyinfowindow.h"
#include "ui_modifyinfowindow.h"
#include "publicstruct.h"
#include "mytcpsocket.h"

#include <QDate>
#include <QFile>

ModifyInfoWindow::ModifyInfoWindow(struct st_personData _userinfo,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ModifyInfoWindow)
{
    ui->setupUi(this);
    // 窗口渲染
    setQssStyle(QString("../style/ModifyInfoWindow.qss"),this);

    // 无边框
    this->setWindowFlags(Qt::FramelessWindowHint);

    userinfo = _userinfo;

    ui->lab_uid->setText(QString::number(userinfo.dd_num));
    ui->le_nick->setText(userinfo.nick);
    ui->cb_sex->setCurrentText(userinfo.sex);
    ui->te_gxqm->setText(userinfo.gxqm);
    ui->le_phone->setText(userinfo.phone);
    ui->le_email->setText(userinfo.email);
    ui->le_home->setText(userinfo.city);
    QStringList bl = userinfo.birthday.split('-');
    ui->de_birth->setDate(QDate(bl.at(0).toInt(),bl.at(1).toInt(),bl.at(2).toInt()));

    QStringList items;
    items<<"男"<<"女";
    ui->cb_sex->addItems(items);
}

ModifyInfoWindow::~ModifyInfoWindow()
{
    delete ui;
}


void ModifyInfoWindow::on_btn_close_clicked()
{
    this->close();
}


void ModifyInfoWindow::on_btn_min_clicked()
{
    this->showMinimized();
}


void ModifyInfoWindow::on_btn_close_2_clicked()
{
    this->close();
}


void ModifyInfoWindow::on_btn_save_clicked()
{
    // 获取用户的信息
    QVariantMap map;
    map["cmd"] = "modify_user_info";
    map["dd_num"]=ui->lab_uid->text().toInt();
    map["nick"]=ui->le_nick->text();
    map["sex"]=ui->cb_sex->currentText();
    map["phone"]=ui->le_phone->text();
    map["email"]=ui->le_email->text();
    map["city"]=ui->le_home->text();
    map["gxqm"]=ui->te_gxqm->toPlainText();
    map["birthday"]=ui->de_birth->text();

    GlobalObject::getGlobalObject()->sendRequest(map);

    this->close();
}

